<template>
  <div>
    <MBX level1="数据统计" level2="数据报表"></MBX>
    <!-- 图表展示区  -->
    <el-card class="mt15">
      <div ref="myChartDom" style="width: 100%; height: 400px"></div>
    </el-card>
  </div>
</template>

<script>
//引入echarts
import * as echarts from "echarts";
export default {
  name: "reports",
  data() {
    return {
      myChart: null,
      //图表固定数据
      preChartData:{
        title: {
          text: '用户来源'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            }
          }
        },
        grid: {
          left: '4%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ]
      }
    };
  },
  mounted() {
    //console.log('this.$refs.myChartDom:',this.$refs.myChartDom)
    this.getChart();

  },
  methods: {
    async getChart() {
      //1.获取dom
      const myChartDom = this.$refs.myChartDom;
      //2.初始化ehcarts图表
      this.myChart = echarts.init(myChartDom);

      //获取后台返回的图表数据
      const res=await this.$API.getGoodsReportAPI()
      console.log('获取后台返回的图表数据:',res)

      //合并固定数据和后台返回的图表数据
      const mergeChartData={...this.preChartData,...res}

      //3.配置图表
      const options = mergeChartData

      //4.渲染图表
      this.myChart.setOption(options);
    },
  },
};
</script>

<style lang="scss" scoped></style>
